/*
 * MainWindow.cpp
 *
 *  Created on: 25.11.2011
 *      Author: Tim
 */
#include "MainWindow.h"

	MainWindow::MainWindow() {

	}

	void MainWindow::initGlut(){
			int argc=0;
			char **argv="";

			glutInit(&argc, argv);
			glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
			glutInitWindowPosition(100,100);
			glutInitWindowSize(762,567);
			glutCreateWindow("Viewer");
	}
	void MainWindow::initCallbacks(){
		glutDisplayFunc(render);

		glutReshapeFunc(reshape);

		glutKeyboardFunc(keyPressed);

		// enter GLUT event processing cycle
		glutMainLoop();
	}

	void MainWindow::keyPressed(unsigned char key, int x, int y){
		std::cout <<  key << " " << std::lend;
	}

	void MainWindow::render(){


			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			glBegin(GL_TRIANGLES);
				glVertex3f(-0.5,-0.5,0.0);
				glVertex3f(0.5,0.0,0.0);
				glVertex3f(0.0,0.5,0.0);
			glEnd();

			glutSwapBuffers();

	}

	void MainWindow::reshape(int w, int h){
		// Prevent a divide by zero, when window is too short
			// (you cant make a window of zero width).
			if(h == 0)
				h = 1;
			float ratio = 1.0* w / h;

			// Use the Projection Matrix
			glMatrixMode(GL_PROJECTION);

		    // Reset Matrix
			glLoadIdentity();

			// Set the viewport to be the entire window
			glViewport(0, 0, w, h);

			// Set the correct perspective.
			gluPerspective(45,ratio,1,1000);

			// Get Back to the Modelview
			glMatrixMode(GL_MODELVIEW);
	}

